// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import VirtualItem from "../../ui/VirtualItem";
import { VirtualArgs } from "../../ui/VirtualList";

const {ccclass, property} = cc._decorator;

export interface SearchConfigArgs extends VirtualArgs {
    name: string;
    clickCallback: any;
    deleteCallback: any;
}


@ccclass
export default class SearchConfigItem extends VirtualItem<SearchConfigArgs> {

    @property(cc.Label)
    labelName: cc.Label = null;

    @property(cc.Button)
    btnDelete: cc.Button = null;

    clickCallback: any = null;
    deleteCallback: any = null;

    public onRefresh(args: SearchConfigArgs) {
        this.labelName.string = args.name;
        this.clickCallback = args.clickCallback;
        this.deleteCallback = args.deleteCallback;
    }

    public onBtnDelete () {
        if (this.deleteCallback) {
            this.deleteCallback(this.dataIdx);
        }
    }

    public onBtnClick () {
        if (this.clickCallback) {
            this.clickCallback(this.dataIdx);
        }
    }

    // update (dt) {}
}
